<!-- 车辆管理 -->
<template>
  <div class="dashboard-container driver customer-list-box">
    <!-- 车型管理 -->
    <div class="top">
      <el-form
        ref="From"
        :model="form"
      >
        <el-row
          type="flex"
          justify="space-between"
        >
          <el-form-item
            label-width="12vh"
            label="司机账号:"
          >
            <el-input
              v-model="params.account"
              prop="account"
              placeholder="请输入司机账号"
              style="width: 20vw"
            />
          </el-form-item>
          <el-form-item
            label-width="12vh"
            label="司机姓名:"
          >
            <el-input
              v-model="params.name"
              placeholder="请输入司机账号"
              style="width: 20vw"
            />
          </el-form-item>
          <el-form-item
            label-width="13vh"
            label="司机手机号:"
          >
            <el-input
              v-model="params.phone"
              placeholder="请输入司机手机号"
              style="width: 20vw"
            />
          </el-form-item>
        </el-row>
        <el-row
          type="flex"
          justify="right"
        >
          <el-form-item
            label="所属机构:"
            label-width="12vh"
            style="margin-right: 2vw;"
          >
            <treeselect
              v-model="params.agentId"
              :options="agencyOptions"
              :normalizer="normalizer"
              :searchable="true"
              style="width: 100%"
              placeholder="请选择所属机构"
              no-options-text="暂无数据"
              no-results-text="暂无数据"
              @select="selectStartAgency"
              @open="open"
              @close="close"
            />
            <img
              ref="arrow"
              src="@/assets/pullDown.png"
              style="
                      position: absolute;
                      width: 18px;
                      height: 18px;
                      right: 9px;
                      top: 12px;
                      cursor: pointer;
                      pointer-events: none;
                      transition-duration: 0.3s;
                    "
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              style="margin-left: 20px"
              @click="doSearch"
            >搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button
              style="margin-left: 20px"
              @click="resetting"
            >重置</el-button>
          </el-form-item>
        </el-row>
        <!-- 查询 -->
      </el-form>
    </div>
    <div class="table">
      <el-table
        style="width: 100%"
        :data="DriverList"
      >
        <el-table-column
          type="index"
          label="序号"
        />
        <el-table-column
          label="司机账号"
          prop="account"
        />
        <el-table-column
          label="司机姓名"
          prop="name"
        />
        <el-table-column
          label="司机电话"
          prop="mobile"
        />
        <el-table-column
          label="关联车辆"
          prop="truck.licensePlate"
        />
        <el-table-column
          label="所属机构"
          prop="agency.name"
        />
        <el-table-column
          label="操作"
          fixed="right"
          width="120"
        >
          <template #default="scope">
            <el-button
              size="mini"
              type="text"
              @click="look(scope.row.userId)"
            >查看</el-button>
            <el-button
              size="mini"
              type="text"
            >配置车辆</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-container">
      <el-pagination
        :current-page="params.page"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"

        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
// 树形图
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Treeselect from '@riophae/vue-treeselect'
import { agencyList } from '@/api/institutions'
// 司机列表
import { driverList } from '@/api/transit'
// import Treeselect from '@riophae/vue-treeselect'
export default {
  name: 'Courses',
  components: {
    Treeselect
  },
  data() {
    return {
      params: {
        page: 1,
        pageSize: 10,
        account: '',
        phone: null,
        name: null,
        workStatus: null,
        agentId: null
      },
      normalizer(node) {
        return {
          id: node.id,
          label: node.name,
          children: node.children
        }
      },
      agencyOptions: [],
      form: {},
      total: 0,
      DriverList: []
    }
  },
  created() {
    this.driverListApi()
    this.getAgencyList()
  },
  methods: {
    // 获取分页数据
    async  driverListApi  () {
      const res = await driverList(this.params)
      console.log(res)
      this.DriverList = res.data.items
      this.total = +res.data.counts
    },
    // 每页条数
    async  handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.params.pageSize = val
      await this.driverListApi()
    },
    // 当前页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.params.page = val
      this.driverListApi()
    },
    // 搜索
    doSearch() {
      this.params.page = 1
      this.driverListApi()
    },
    // 重置
    resetting() {
      // this.$refs.From.resetFields()
      this.params.account = ''
      this.params.phone = ''
      this.params.name = ''
    },
    // 查看
    look(id) {
      console.log(id)
      this.$router.push(`driver-detail?id=${id}`)
    },
    open() {
      this.$refs.arrow.style.transform = 'rotate(-180deg)'
    },
    close() {
      this.$refs.arrow.style.transform = 'rotate(0deg)'
    },
    selectStartAgency(val) {
      this.searchForm.agentId = val.id
    },
    // 获取起始/目的地机构列表数据
    async getAgencyList() {
      const { data: res } = await agencyList()
      // 获取数据给options
      this.agencyOptions = JSON.parse(res)
    }
  }
}
</script>
<style
      rel="stylesheet/scss"
      lang="scss"
      scoped
    >
    .page-container{
      padding-bottom: 60px;
      /* padding:4px 0px 0px 60px ; */
      text-align: right;
    }
      .add-btn{
      margin-bottom: 20px;
      }
      .alert {
      margin: 10px 0px;
      }
      .pagination {
      margin-top: 20px;
      padding-bottom: 0px;
      }
      .top{
      margin-top: 40px;
      }
      .el-select {
      width: 100%;
      }

      .car-models ::v-deep .el-table td,
      .el-table th {
      padding: 12px 0;
      min-width: 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      text-overflow: ellipsis;
      vertical-align: middle;
      position: relative;
      text-align: left;
      overflow: hidden;
      }
      .car-models {
      ::v-deep .el-dialog__title {
      width: 73px;
      height: 25px;
      font-size: 18px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: left;
      color: #20232a;
      line-height: 25px;
      letter-spacing: 0px;
      }
      ::v-deep .el-dialog__body {
      text-align: center;
      padding: 40px 60px 0 30px;
      }
      .warn-img {
      width: 40px;
      }
      p {
      height: 24px;
      font-size: 16px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      color: #818693;
      line-height: 24px;
      }
      }
</style>

